package com.cho.core.run;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class RunGUI extends JFrame implements ActionListener{
    
    private JFileChooser jfc = new JFileChooser();
    private JButton jbt_open = new JButton("열기");
    private JButton jbt_save = new JButton("저장");
    private JLabel jlb = new JLabel(" ");
    
    public RunGUI(){
            super("test");
            this.init();
            this.start();
            this.setSize(400,200);
            this.setVisible(true);
    }
    public void init(){
            getContentPane().setLayout(new FlowLayout());
            add(jbt_open);
            add(jbt_save);
            add(jlb);
    }
    public void start(){
            jbt_open.addActionListener(this);
            jbt_save.addActionListener(this);

            //jfc.setFileFilter(new FileNameExtensionFilter("txt", "txt"));
            // 파일 필터
            jfc.setMultiSelectionEnabled(false);//다중 선택 불가
            
            jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    }

    @Override
    public void actionPerformed(ActionEvent arg0) {
            // TODO Auto-generated method stub
            if(arg0.getSource() == jbt_open){
                    if(jfc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION){
                            // showopendialog 열기 창을 열고 확인 버튼을 눌렀는지 확인
                            jlb.setText("열기 경로 : " + jfc.getSelectedFile().toString());
                    }
            }else if(arg0.getSource() == jbt_save){
                    if(jfc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION){
                            // showSaveDialog 저장 창을 열고 확인 버튼을 눌렀는지 확인
                            jlb.setText("저장 경로 : " + jfc.getSelectedFile().toString() + "." + jfc.getFileFilter().getDescription());
                    }
            }
    }

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		RunGUI c = new RunGUI();

	}

}
